package info.opensoaring.api.igc;

import info.opensoaring.util.igc.LogParser.TLC;

import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;

public class Fix implements Serializable {

    private static final long serialVersionUID = 2951532274312703771L;

    public static enum FixValidity {
	A, V
    };

    private Date time;

    private double latitude;

    private double longitude;

    private FixValidity fixValidity;

    private int pressureAltitude;

    private int gnssAltitude;

    private HashMap<TLC, String> extensions = new HashMap<TLC, String>();

    public Fix() {

    }

    public Fix(double latitude, double longitude, int gnssAltitude) {
	this.latitude = latitude;
	this.longitude = longitude;
	this.gnssAltitude = gnssAltitude;
    }

    public Fix(Date time, double latitude, double longitude, FixValidity fixValidity,
	    int pressureAltitude, int gnssAltitude) {
	this.time = time;
	this.latitude = latitude;
	this.longitude = longitude;
	this.fixValidity = fixValidity;
	this.pressureAltitude = pressureAltitude;
	this.gnssAltitude = gnssAltitude;
    }

    public HashMap<TLC, String> getExtensions() {
	return extensions;
    }

    public void setExtensions(HashMap<TLC, String> extensions) {
	this.extensions = extensions;
    }

    public void addExtension(TLC extension, String value) {
	extensions.put(extension, value);
    }

    public String getExtension(TLC extension) {
	if (extensions.keySet().contains(extension)) {
	    return extensions.get(extension);
	}
	return null;
    }

    public Date getTime() {
	return time;
    }

    public void setTime(Date time) {
	this.time = time;
    }

    public double getLatitude() {
	return latitude;
    }

    public double getLatitudeRadians() {
	return Math.toRadians(latitude);
    }

    public void setLatitude(float latitude) {
	this.latitude = latitude;
    }

    public double getLongitude() {
	return longitude;
    }

    public double getLongitudeRadians() {
	return Math.toRadians(longitude);
    }

    public void setLongitude(float longitude) {
	this.longitude = longitude;
    }

    public FixValidity getFixValidity() {
	return fixValidity;
    }

    public void setFixValidity(FixValidity fixValidity) {
	this.fixValidity = fixValidity;
    }

    public int getPressureAltitude() {
	return pressureAltitude;
    }

    public void setPressureAltitude(int pressureAltitude) {
	this.pressureAltitude = pressureAltitude;
    }

    public int getGnssAltitude() {
	return gnssAltitude;
    }

    public void setGnssAltitude(int gnssAltitude) {
	this.gnssAltitude = gnssAltitude;
    }
}
